#!/bin/bash

docker pull elasticsearch:7.16.2

docker run --name elasticsearch --restart=always \
-p 9200:9200 \
-p 9300:9300 \
-e "discovery.type=single-node" \
--net mynet \
--ip 172.18.0.6 \
-d elasticsearch:7.16.2

elasticsearchPath=/opt/docker/elasticsearch
elasticsearchConfPath=$elasticsearchPath/config
elasticsearchSourceConfFile=elasticsearch:/usr/share/elasticsearch/config/elasticsearch.yml
elasticsearchTargetConfFile=$elasticsearchConfPath/elasticsearch.yml

mkdir -p $elasticsearchPath
mkdir -p $elasticsearchConfPath


docker cp $elasticsearchSourceConfFile $elasticsearchConfPath

cat >> $elasticsearchTargetConfFile <<EOF

xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true

EOF

docker cp $elasticsearchTargetConfFile $elasticsearchSourceConfFile
docker restart elasticsearch

docker exec -it elasticsearch /bin/bash
## /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
#Please confirm that you would like to continue [y/N]y
#
#然后下面一路都是密码:123456
#Enter password for [elastic]:
#Reenter password for [elastic]:
#Enter password for [apm_system]:
#Reenter password for [apm_system]:
#Enter password for [kibana_system]:
#Reenter password for [kibana_system]:
#Enter password for [logstash_system]:
#Reenter password for [logstash_system]:
#Enter password for [beats_system]:
#Reenter password for [beats_system]:
#Enter password for [remote_monitoring_user]:
#Reenter password for [remote_monitoring_user]:


##elastic：内置超级用户
#kibana：仅可用于kibana用来连接elasticsearch并与之通信, 不能用于kibana登录
#logstash_system：用于Logstash在Elasticsearch中存储监控信息时使用

##http://192.168.202.10:9200


#下面是 创建 索引
#PUT test_product
#{
#  "mappings": {
#    "properties": {
#      "title": {
#        "type": "text"
#      },
#      "sub_title": {
#        "type": "text"
#      },
#      "pic": {
#        "type": "text"
#      },
#      "price": {
#        "type": "double"
#      }
#    }
#  }
#}
#
#GET test_product/_mapping
#
#GET test_product/_search
#
#INSERT INTO product ( id, title, sub_title, price, pic ) VALUES ( 5, '小米8', ' 全面屏游戏智能手机 6GB+64GB', 1999.00, NULL );
#INSERT INTO product ( id, title, sub_title, price, pic ) VALUES ( 6, '小米9', '9 全面屏游戏智能手机 6GB+64GB', 2999.00, NULL );
#INSERT INTO product ( id, title, sub_title, price, pic ) VALUES ( 7, '小米10', '10 全面屏游戏智能手机 6GB+64GB', 3999.00, NULL );

#删除索引某行数据
#POST bi_daily_unit/_delete_by_query
#{
#  "query": {
#    "term": {
#      "date": "2022-07-19"
#    }
#  }
#}